package com.mdd.front.controller;

import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.front.LikeFrontThreadLocal;
import com.mdd.front.service.IMemberService;
import com.mdd.front.validate.common.PageValidate;
import com.mdd.front.validate.member.MemberAuthValicate;
import com.mdd.front.validate.member.MemberExamineValicate;
import com.mdd.front.validate.member.MemberSearchValidate;
import com.mdd.front.vo.member.MemberListedVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/member")
@Api(tags = "社团成员认证")
public class MemberController {

    @Resource
    IMemberService iMemberService;

    @PostMapping("/auth/apply")
    @ApiOperation(value="社团成员认证申请")
    public AjaxResult memberApply(@Validated @RequestBody MemberAuthValicate valicate){
        Integer userId = LikeFrontThreadLocal.getUserId();
        valicate.setUserId(userId);
        iMemberService.memberApply(valicate);
        return AjaxResult.success();
    }

    @GetMapping("/lists")
    @ApiOperation(value="赛事列列表")
    public AjaxResult<PageResult<MemberListedVo>> list(@Validated PageValidate pageValidate,
                                                       @Validated MemberSearchValidate valicate) {
        Integer userId = LikeFrontThreadLocal.getUserId();
        valicate.setUserId(userId);
        PageResult<MemberListedVo> list = iMemberService.list(pageValidate, valicate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="文章详情")
    public AjaxResult<MemberListedVo> detail() {
        Integer userId = LikeFrontThreadLocal.getUserId();
        MemberListedVo vo = iMemberService.detail(userId);
        return AjaxResult.success(vo);
    }

    @PostMapping("/examine")
    @ApiOperation(value="社团成员认证申请")
    public AjaxResult examine(@Validated @RequestBody MemberExamineValicate valicate){
        iMemberService.memberExamine(valicate);
        return AjaxResult.success();
    }

}
